/**
 * msg***:自动消失提示消息
 * alert***：需要点击确认的提示消息
 */

(function ($) {
    $.extend({
        popup: {
            open: function (title, url, width, height) {
                var index = layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
//                    area: [document.documentElement.clientWidth,document.documentElement.clientHeight ],
                    fix: true,
                    //不固定
                    maxmin: false,
                    shade: 0.3,
                    title: title,
                    content: url,
                    btn: ['确定', '关闭'],
                    // 弹层外区域关闭
                    shadeClose: true,
                    yes: function (index, layero) {
                        var iframeWin = layero.find('iframe')[0];
                        iframeWin.contentWindow.submitHandler();
                    },
                    cancel: function (index) {
                        return true;
                    }
                });
                return index;
            }, openDefault: function (title, url) {
                var width, height;
                //如果是移动端，就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                ;
                if ($.common.isEmpty(title)) {
                    title = false;
                }
                ;
                if ($.common.isEmpty(url)) {
                    url = "/404.html";
                }
                ;
                if ($.common.isEmpty(width)) {
                    width = popup_default.width;
                }
                ;
                if ($.common.isEmpty(height)) {
                    height = popup_default.height;
                }
                var index = this.open(title, url, width, height);
            },
            // 弹出层全屏
            openFull: function (title, url, width, height) {
                //如果是移动端，就使用自适应大小弹窗
                if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                    width = 'auto';
                    height = 'auto';
                }
                ;
                if ($.common.isEmpty(title)) {
                    title = false;
                }
                ;
                if ($.common.isEmpty(url)) {
                    url = "/404.html";
                }
                ;
                if ($.common.isEmpty(width)) {
                    width = document.documentElement.clientWidth;
                }
                ;
                if ($.common.isEmpty(height)) {
                    height = (document.documentElement.clientHeight - 100);
                }
                var index = this.open(title, url, width, height);
                layer.full(index);
            },
             openOptions: function (options) {
                var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
                var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
                var _width = $.common.isEmpty(options.width) ? "800" : options.width;
                var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
                layer.open({
                    type: 2,
                    maxmin: true,
                    shade: 0.3,
                    title: _title,
                    fix: false,
                    area: [_width + 'px', _height + 'px'],
                    content: _url,
                    shadeClose: true,
                    btn: ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
                    yes: function (index, layero) {
                        options.callBack(index, layero)
                    }, cancel: function () {
                        return true;
                    }
                });
            }
        },
        operation: {
            saveModal: function (url, data, aftSucCbk) {
//                var loadindex;
                var config = {
                    url: url,
                    type: "post",
                    dataType: "json",
                    data: data,
                    aftSucCbk: aftSucCbk,
                    beforeSend: function () {
                    },
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.alertMsg.msgSuccess(result.msg)
                            if (this.aftSucCbk) {
                                this.aftSucCbk();
                            }
                        } else if (result.code == web_status.FAIL) {
                            $.alertMsg.alertError(result.msg);
                        } else {
                            $.alertMsg.alertWarning(result.msg);
                        }
                    }
                };
                $.ajax(config);
            }
        }
    });
})(jQuery);
/** 弹窗状态码 */
popup_default = {
    width: 655,
    height: 500
};